package com.lyk.swap.orm;

import java.util.Date;

import com.lyk.swap.PeriodLabel;
import com.lyk.swap.RiskProfit;
import com.lyk.swap.struts.action.BaseAction;

/**
 * Future entity. @author MyEclipse Persistence Tools
 */

public class Future implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = -3194187791884134921L;
	private static final String BUY = "BUY";
	private static final String SELL = "SELL";
	private Integer futureid;
	private Trader trader;
	private Product product;
	private Boolean buy;
	private Date period;
	private Integer quantity;
	private Double price;
	private Double currentprice;
	private boolean risk = true;
	private String murl;

	// Constructors

	/** default constructor */
	public Future() {
	}

	/** full constructor */
	public Future(Trader trader, Product product,
			Boolean buy, Date period, Integer quantity, Double price) {
		super();
		this.trader = trader;
		this.product = product;
		this.buy = buy;
		this.period = period;
		this.quantity = quantity;
		this.price = price;
	}

	// Property accessors

	public Integer getFutureid() {
		return this.futureid;
	}

	public void setFutureid(Integer futureid) {
		this.futureid = futureid;
	}

	public Trader getTrader() {
		return trader;
	}

	public void setTrader(Trader trader) {
		this.trader = trader;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Boolean getBuy() {
		return this.buy;
	}

	public void setBuy(Boolean buy) {
		this.buy = buy;
	}

	public Date getPeriod() {
		return this.period;
	}

	public void setPeriod(Date period) {
		this.period = period;
	}

	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public Double getPrice() {
		return this.price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public void setCurrentprice(Double currentprice) {
		this.currentprice = currentprice;
	}

	public String getMurl() {
		if (null == murl) {
			setMurl();
		}
		return murl;
	}

	@SuppressWarnings("deprecation")
	private void setMurl() {
		StringBuilder sb = new StringBuilder(RiskProfit.MURL);
		sb.append(RiskProfit.TICKERHEDDER);
		sb.append(BaseAction.TICKER[period.getMonth()]);
		sb.append(period.getYear() - 110);
		murl = sb.toString();
	}

	public String getFormatBuy() {
		return buy ? BUY : SELL;
	}

	public String getFormatPrice() {
		return BaseAction.format(price);
	}

	public String getFormatPeriod() {
		return new PeriodLabel(period).toString();
	}

	public String getProfit() {
		if (null == currentprice) {
			return "-";
		}
		double profit = currentprice - price;
		profit *= quantity;
		if (!buy) {
			profit *= -1;
		}
		return BaseAction.format(profit);
	}

	public boolean isRisk() {
		return risk;
	}

	public void setRisk(boolean risk) {
		this.risk = risk;
	}

	public int getFormatRisk() {
		return risk ? quantity : 0;
	}

	public String getFormatCode() {
		return product.getCode();
	}

}